package cn.it.controller;

import cn.it.services.ISearchServices;
import cn.it.util.CustomerNameAndId;
import cn.it.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Controller
public class SearchController {

    @Autowired
    private ISearchServices iSearchServices;

    @RequestMapping("/search")
    public String search(Model model){
        model.addAttribute("data",queryAllCustomer());
        return "index";
    }

    @RequestMapping("/queryAllCustomer")
    @ResponseBody
    public Result queryAllCustomer(){
        List<CustomerNameAndId> list = iSearchServices.queryAllCustomer();
        return new Result(200,"查询到数据",list);
    }
    @RequestMapping("/searchCustomerById")
    @ResponseBody
    public Result searchCustomerById(Integer checkCode){
        Result result = iSearchServices.searchCustomerById(checkCode);
        return result;
    }
}
